using UnityEngine;

namespace GridSystem
{
    /// <summary>
    /// 运行时的单元格状态
    /// </summary>
    public enum CellState
    {
        Unoccupied, // 未被占用
        Occupied    // 已被占用
    }

    /// <summary>
    /// 【运行时】代表GridSurface上的单个逻辑单元格。
    /// </summary>
    public class Cell
    {
        public Vector2Int LocalPosition { get; }
        public CellState State { get; private set; }
        public PlaceableObject OccupyingObject { get; private set; }

        public Cell(Vector2Int localPosition)
        {
            LocalPosition = localPosition;
            State = CellState.Unoccupied;
            OccupyingObject = null;
        }

        /// <summary>
        /// 尝试占用此单元格
        /// </summary>
        public bool Occupy(PlaceableObject obj)
        {
            if (State == CellState.Occupied) return false;
            State = CellState.Occupied;
            OccupyingObject = obj;
            return true;
        }

        /// <summary>
        /// 释放此单元格
        /// </summary>
        public void Free()
        {
            State = CellState.Unoccupied;
            OccupyingObject = null;
        }
    }
}